package com.ruoyi.web;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.Seeker;
import com.ruoyi.system.service.ISeekerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@RestController
public class AddResumeController extends BaseController {
    @Autowired
    private ISeekerService resumeService;

    @RequestMapping("/addresume")
    public AjaxResult addResume(
            @RequestParam String name,
            @RequestParam String telephone,
            @RequestParam String pwd,
            @RequestParam String email,
            @RequestParam String currentcity,
            @RequestParam String gender,
            @RequestParam String birth,
            @RequestParam String edulevl,
            @RequestParam String major,
            @RequestParam String studyperiod,
            @RequestParam String schoolname,
            @RequestParam String isfresh,
            @RequestParam String expjobtype,
            @RequestParam String expposition,
            @RequestParam String exploc,
            @RequestParam String expindus,
            @RequestParam String expsalary,
            @RequestParam String selfdesc) {
        System.out.println("添加新简历，现在在映射函数中");
        Seeker resume = new Seeker();

        resume.setSeekerName(name);
        resume.setSeekerTel(telephone);
        resume.setSeekerPwd(pwd);
        resume.setSeekerEmail(email);
        resume.setSeekerCity(currentcity);
        resume.setSeekerGender(gender);

        // 将 birth 从 String 转换为 Date
        try {
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            Date birthDate = dateFormat.parse(birth);
            resume.setSeekerDob(birthDate);
        } catch (ParseException e) {
            return AjaxResult.error("Invalid birth date format. Expected format: yyyy-MM-dd");
        }

        resume.setSeekerEdulvl(edulevl);
        resume.setSeekerMaj(major);
        resume.setSeekerStudyper(studyperiod);
        resume.setSeekerSchname(schoolname);
        resume.setSeekerIsfreshman(isfresh);
        resume.setSeekerExpjobtype(expjobtype);
        resume.setSeekerExppos(expposition);
        resume.setSeekerExpworkloc(exploc);
        resume.setSeekerExpind(expindus);
        resume.setSeekerAdv(expsalary);
        resume.setSeekerAdv(selfdesc);

        return toAjax(resumeService.insertSeeker(resume));
    }
}
